package com.ybkj.chat.module.friend_center.fragment;

import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.ImageView;

import com.androidkun.xtablayout.XTabLayout;
import com.ybkj.chat.R;
import com.ybkj.chat.base.BaseMvpFragment;
import com.ybkj.chat.manager.ActivityManager;
import com.ybkj.chat.module.dynamic.activity.AddFriendActivity;
import com.ybkj.chat.module.dynamic.activity.AddGroupActivity;
import com.ybkj.chat.module.dynamic.activity.CreatGroupActivity;
import com.ybkj.chat.module.friend_center.activity.MyQRcodeActivity;
import com.ybkj.chat.module.friend_center.activity.SearchGroupActivity;
import com.ybkj.chat.module.main.fragment.AllFriendFragment;
import com.ybkj.chat.ui.adapter.ViewPagerAdapter;
import com.ybkj.chat.ui.dialog.PpwMessageMenu;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 圈友
 */
public class FriendFragment extends BaseMvpFragment {
    //搜索
    @BindView(R.id.iv_search)
    ImageView ivSearch;
    //添加
    @BindView(R.id.et_add)
    ImageView etAdd;
    @BindView(R.id.tab)
    XTabLayout tab;
    @BindView(R.id.pager)
    ViewPager pager;


    private ViewPagerAdapter viewPagerAdapter;
    private PpwMessageMenu mPpwMessageMenu;

    @Override
    protected void injectPresenter() {

    }

    @Override
    protected void initView() {
        initPop();
        viewPagerAdapter = new ViewPagerAdapter(this.getChildFragmentManager());
        tab.addTab(tab.newTab().setText("全部圈友"));
        tab.addTab(tab.newTab().setText("圈群"));
        tab.addTab(tab.newTab().setText("关注"));
        tab.addTab(tab.newTab().setText("粉丝"));

        AllFriendFragment allFriendFragment = new AllFriendFragment();
        CircleGroupFragment groupFragment = new CircleGroupFragment();
        FollowFragment followFragment2 = new FollowFragment();
        FansFragment fansFragment = new FansFragment();
        viewPagerAdapter.addFragment(allFriendFragment, "全部圈友");
        viewPagerAdapter.addFragment(groupFragment, "圈群");
        viewPagerAdapter.addFragment(followFragment2, "关注");
        viewPagerAdapter.addFragment(fansFragment, "粉丝");
        pager.setAdapter(viewPagerAdapter);
        if (tab != null) {
            tab.setupWithViewPager(pager);
        }
    }

    @Override
    protected void initData() {

    }

    @Override
    public int getLayoutId() {
        return R.layout.fragment_friend;
    }

    @Override
    protected String getSimpleNme() {
        return null;
    }

    /**
     * 点击事件
     *
     * @param view
     */
    @OnClick({R.id.iv_search, R.id.et_add})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            //圈友搜索
            case R.id.iv_search:
                ActivityManager.gotoActivity(mContext, SearchGroupActivity.class);
                break;
            case R.id.et_add:
                mPpwMessageMenu.showAsDropDown(etAdd, 0, 0);
                mPpwMessageMenu.setBackgroundAlpha(mContext, 0.5f);
                break;

        }
    }

    private void initPop() {
        mPpwMessageMenu = new PpwMessageMenu(mContext);
        mPpwMessageMenu.setOnMenuButtonCLickListener(new PpwMessageMenu.OnMenuButtonClickListener() {
            @Override
            public void onQrButtonClick() {

            }

            @Override
            public void onAddFriendButtonClick() {
                ActivityManager.gotoActivity(mContext, AddFriendActivity.class);
            }

            @Override
            public void onCreatGroupButtonClick() {
                ActivityManager.gotoActivity(mContext, CreatGroupActivity.class);

            }

            @Override
            public void onAddGroupButtonClick() {
                ActivityManager.gotoActivity(mContext, AddGroupActivity.class);
            }

            @Override
            public void onMyQrCodeButtonClick() {
                ActivityManager.gotoActivity(mContext, MyQRcodeActivity.class);
            }
        });
    }
}
